﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using WpfStarterKit.Framework.Navigation;
using System.Windows;

namespace WpfStarterKit.SampleApplication.Screens.LongRunningOperation
{
    public class SampleLongRunningOperationHandler : LongRunningOperationManager
    {
        private UIElement _waitElement;
        private TextBlock _waitText;

        public SampleLongRunningOperationHandler(FrameworkElement element) : base()
        {
            _waitElement = element;
            _waitText = element.FindName("WaitText") as TextBlock;
        }

        public override void LongRunningOperationStarted(LongRunningOperationAttribute data)
        {
            base.LongRunningOperationStarted(data);

            if(_waitText != null && String.IsNullOrEmpty(data.Message) == false)
            {
                _waitText.Text = data.Message;
            }
            else
            {
                _waitText.Text = "Please wait";
            }

            _waitElement.Visibility = Visibility.Visible;
        }

        public override void LongRunningOperationCompleted(LongRunningOperationAttribute data)
        {
            base.LongRunningOperationCompleted(data);
            _waitElement.Visibility = Visibility.Collapsed;
        }
    }
}
